package com.zzptc.zzsgz.bdsjws.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.utils.DanceWageTimer;
import com.zzptc.zzsgz.bdsjws.views.RatingBar;
import com.zzptc.zzsgz.bdsjws.views.RatingView;

import java.util.Random;

import butterknife.BindView;
import butterknife.OnClick;

public class MainActivity extends BaseActivity {
    @BindView(R.id.re_count)
    RatingView reCount;
    @BindView(R.id.activity_main)
    LinearLayout activityMain;
    @BindView(R.id.tv_num)
    TextView tvNum;
    int one;
    int two;
    int three;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //发送
        Intent intent = new Intent();
        intent.setAction("UpdateVersion");
        sendBroadcast(intent);
        initData();
    }

    @Override
    public int getContentXML() {
        return R.layout.activity_main;
    }

    @Override
    public void initData() {

    }

    @Override
    public void intView() {
        one = new Random().nextInt(10) + 1;
        two = new Random().nextInt(10) + 1;
        three = new Random().nextInt(10) + 1;
        //根据产生的随机数来定（>8高，<5低，<5==>8中
        reCount.addRatingBar(new RatingBar(one, one > 8 ? "清晰度高" : (one <= 5) ? "清晰度低" : "清晰度中"));
        reCount.addRatingBar(new RatingBar(two, two > 8 ? "流畅度高" : (two <= 5) ? "流畅度低" : "流畅度中"));
        reCount.addRatingBar(new RatingBar(three, three > 8 ? "安全度高" : (three <= 5) ? "安全度低" : "安全度中"));
        reCount.show();
        //监听
        reCount.setAnimatorListener(new RatingView.AnimatorListener() {
            @Override
            public void onRotateStart() {

            }

            @Override
            public void onRotateEnd() {
                //跳数的效果
                int sum = (int) ((one * 0.5 + two * 0.3 + three * 0.2) * 10);
                //tvNum.setText(sum+"");
                long totalExecuteTime = DanceWageTimer.getTotalExecuteTime(sum, 20);
                DanceWageTimer danceWageTimer = new DanceWageTimer(totalExecuteTime, 20, tvNum, sum);
                danceWageTimer.start();
            }

            @Override
            public void onRatingStart() {

            }

            @Override
            public void onRatingEnd() {

            }
        });
    }


    @OnClick(R.id.iv_user)
    public void onViewClicked(View view) {
        Intent intent = new Intent(this, MyActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.text_box)
    public void onViewClicked() {
        startActivity(new Intent(this,BoxActivity.class));
    }
}
